<template>
  <Card style="width:850px;margin: auto;">
    <Form :model="formLeft" label-position="left" :rules="validateLibForm" :label-width="150" style="width: 300px;margin: auto;">

      <FormItem label="物料类型名称:" prop="typeName">
        <Input v-model="formLeft.typeName" :maxlength="10"></Input>
      </FormItem>

      <FormItem label="描述:" prop="describe">
        <Input v-model="formLeft.describe" type="textarea"></Input>
      </FormItem>

      <row type="flex" justify="center">
        <i-col span="20">

        </i-col>
        <i-col span="30">
          <Button type="primary" @click="MaterialTypeUpdateById">修改</Button>
          <Button type="success" style="margin-left: 160px" @click="back">返回</Button>
        </i-col>
      </row>

    </Form>
  </Card>
</template>

<script>
  import {MaterialTypeFindById,MaterialTypeUpdateById} from "../../../api/data"

  export default {
    data() {
      return {
        page: 1,//page 第几页
        pageSize: 10,//pageSize:每页几条数据
        total: 0,
        formLeft: {
          id: '',
          typeName: '',
          describe:'',
        },
        validateLibForm: {
          typeName: [
            {required: true, message: '请输入', trigger: 'blur'}
          ],
        }
      }
    },
    mounted() {
      console.log(this.$route.query.id);
      const idFlag = this.$route.query.id;
      if(idFlag){
        this.formLeft.id = idFlag;
        this.MaterialTypeFindById();
      }
    },
    methods: {
      MaterialTypeUpdateById() {
            if (this.formLeft.typeName !== null && this.formLeft.typeName !== "") {
              MaterialTypeUpdateById(this.formLeft).then(res => {
                  if (res.data.code==0){
                    this.$Message.success("编辑成功");
                    this.$router.go(-1);
                  } else {
                    this.$Message.error( res.data.msg);
                  }
                })
            } else {
              this.$Message.error("物料类型名称不能为空");
            }
      },
      back(){
        this.$router.go(-1);
      },
      MaterialTypeFindById(){
        var data =  {
          id:this.formLeft.id,
        }
        MaterialTypeFindById(data).then(res => {
          this.formLeft = res.data.data;
        })
      }
    },

  }
</script>


